
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package tt.dz.biz.service.rpc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import org.apache.avro.Protocol;
import org.apache.avro.Protocol.Message;
import org.apache.avro.generic.GenericRecord;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.user.IdentityAccountDAO;
import tt.dz.biz.dao.user.OnlineAccountDAO;
import tt.dz.biz.service.card.CardTypeService;
import tt.dz.common.LogUtil;
import tt.dz.common.DzConstants.CardType;
import tt.dz.common.DzErrorCode.CardErrorCode;
import tt.dz.common.DzErrorCode.CommonErrorCode;

@Service("rpcQueryUserIdByCardNoService")
public class RPCQueryUserIdByCardNoService implements RPCBaseService {
    @Resource(
        name = "identityAccountDAO"
    )
    private IdentityAccountDAO identityAccountDAO;
    @Resource(
        name = "cardTypeServiceImpl"
    )
    private CardTypeService cardTypeService;
    @Resource(
        name = "onlineAccountDAO"
    )
    private OnlineAccountDAO onlineAccountDAO;

    public RPCQueryUserIdByCardNoService() {
    }

    public Object execute(Message message, Object request, Protocol protocol) throws Exception {
        Object req = ((GenericRecord)request).get("req");
        JSONObject jsonObj = JSON.parseObject(req.toString());
        String cardNo = jsonObj.getString("cardNo");
        JSONObject resultJson = new JSONObject();
        resultJson.put("isSuccess", Integer.valueOf(0));
        if(StringUtils.isBlank(cardNo)) {
            resultJson.put("errorMsg", CommonErrorCode.PARAM_REQUIRED.getDesc());
            resultJson.put("errorCode", CommonErrorCode.PARAM_REQUIRED.value());
            return resultJson.toJSONString();
        } else {
            String cardType = this.cardTypeService.getCardType(cardNo);
            if(!this.checkCardTypeIsRight(cardType)) {
                resultJson.put("errorMsg", CardErrorCode.CARD_TYPE_ERROR.getDesc());
                resultJson.put("errorCode", CardErrorCode.CARD_TYPE_ERROR.value());
                return resultJson.toJSONString();
            } else {
                try {
                    String userId = "";
                    if(cardType.equals(CardType.IDENTITY_CARD.value())) {
                        userId = this.identityAccountDAO.queryUserIdByCardNo(cardNo);
                    } else if(cardType.equals(CardType.ONLINE_CARD.value())) {
                        userId = this.onlineAccountDAO.queryUserIdByCardNo(cardNo);
                    }

                    resultJson.put("userId", userId == null?"":userId);
                    resultJson.put("isSuccess", Integer.valueOf(1));
                } catch (Exception var10) {
                    LogUtil.error("根据卡号查询userId出错，卡号：" + cardNo);
                    throw var10;
                }

                return resultJson.toJSONString();
            }
        }
    }

    private boolean checkCardTypeIsRight(String cardType) throws Exception {
        boolean cardTypeIsRight = false;
        CardType[] var6;
        int var5 = (var6 = CardType.values()).length;

        for(int var4 = 0; var4 < var5; ++var4) {
            CardType tmp = var6[var4];
            if(tmp.value().equals(cardType)) {
                cardTypeIsRight = true;
                break;
            }
        }

        return cardTypeIsRight;
    }
}

